package com.supertimetable.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

import com.supertimetable.activities.R;
import com.supertimetable.adapter.AutoTextViewAdapter;
import com.supertimetable.bean.Teacher;
import com.supertimetable.db.DBTeacherUtil;

import java.util.ArrayList;

/**
 * Created by Admin on 2018/1/12.
 */

public class Teacher_Fragment extends Fragment {

    private ArrayList<Teacher> teachers;
    private ArrayList<String> tIds = new ArrayList<>();
    private String tId;
    private byte[] imp;

    private ImageView verificationImage;

    private Spinner name = null;


    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_teacher, container, false);

        name = (Spinner) view.findViewById(R.id.name);
        initViews();
        eventsViews();

        verificationImage = (ImageView) view.findViewById(R.id.verificationImage);
        new Thread(){
            @Override
            public void run() {

            }
        }.start();
        verificationImage.setImageDrawable(getResources().getDrawable(R.drawable.verimg));

        return view;
    }
    private void eventsViews() {

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,tIds);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        name.setAdapter(adapter);
        name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                tId = teachers.get(position).gettId().trim();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }

    private void initViews() {
        getTeachers();
        }
    public void getTeachers(){
        teachers = DBTeacherUtil.queryTeachers(getActivity());
        for(Teacher t:teachers){
            Log.i("name",t.gettName());
            String s = t.gettName();
            tIds.add(s);
        }
    }

}


